<?
	require_once('../fun/users.php');
	$results = GetUsers();

?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>&psi; Psychology Database &psi;</title>
<? include ("../inc/required-links.php") ?>
</head>

<body>
<div id="wrapper">
	<div id="l_l"></div> 
    <div id="left">
		<?php include ('../nav/nav.php') ?>
    </div>
    <div id="main">
		<?php include ('../inc/header.php') ?>
        <div id="t_bg"></div>
        <div id="content">
			<div class="otstup">
            	<div id="main_left">
            		<h1 style="text-align:center;">User Informations</h1>
					<div class="corners">
                    	<div class="text">
                			<a href="create.php?returnUrl=<?=$_SERVER['PHP_SELF']?>" role="button" class="btn btn-mini create-link" data-toggle="modal">+ Add New User</a>
                    		<form method="post" action="edit.php">
                			<table class="table-hover" style="color:black; width:100%; text-align:center;" cellpadding="0" cellspacing="0">
                    			<thead>
                    			<tr>
                        			<th>First Name</th><th>Last Name</th><th>Actions</th>
                    			</tr>
                    			</thead>
                    			<tbody>
                   	 		<? while($rs = $results->fetch_assoc()): ?>
                        		<tr>
                            		<td><?=$rs['FirstName']?></td>
                            		<td><?=$rs['LastName']?></td>
                            		<td><?=$rs['Password']?></td>
                            		<td>
                                		<a class="delete-link" href="details.php?id=<?=$rs['id']?>&returnUrl=<?=$_SERVER['PHP_SELF']?>">Details</a>
                                		| <a class="edit-link" href="edit.php?id=<?=$rs['id']?>&returnUrl=<?=$_SERVER['PHP_SELF']?>">Edit</a> |
                                		<a class="delete-link" href="delete.php?id=<?=$rs['id']?>&returnUrl=<?=$_SERVER['PHP_SELF']?>">Delete</a>
                            		</td>
                        		</tr>
                    		<? endwhile; ?>
                    		</tbody>
                			</table>
                			</form>
                        </div>
                    </div>
                </div>
                <div id="right">
					<?php include ('../inc/cat_box1.php') ?>
					<?php include ('../inc/cat_box2.php') ?>
					<?php include ('../inc/cat_box3.php') ?>
					<?php include ('../inc/cat_box4.php') ?>
					<?php include ('../inc/sn_links.php') ?>
                </div>
        		<div class="clear"></div>
        	</div>
        </div>
        <div class="clear"></div>  
        <div id="foot">
        	<?php include ('../inc/footer.php') ?>
		</div>
		<?php include ('../inc/copywright.php') ?>
        </div>
<div class="clear"></div> 
</div>
</body>
</html>
<? include ('../inc/required-js.php'); ?>
<script type="text/javascript">
			function CancelEdit()
			{
				$(".edit-form").prev().show().end().remove();
			}
			function TransformToTr(data)
			{
				return	$(data).find(".control-group")
						.wrapAll("<tr />").wrap("<td />")
						.find("input, select").attr("placeholder",function(){
							return $(this).closest("td").find("label").hide().text();
						})
						.closest("tr").addClass("edit-form");
			}
			$(function(){
				$('table').dataTable();
				$(".close").click(function(){
					$(this).closest(".alert").slideUp();
				});
				
				var settings = {
					backgroundColor: '#FF8888',
					color: '#FFFFFF'
				};
				<? if(isset($_GET['inserted'])): ?>
					$("html, body").animate({scrollTop: $(".info").offset().top}, 2000, 'easeInOutBack');
				<? endif; ?>
				$(".info td").css(settings).delay(2000).animate({backgroundColor: '#FFFFFF', color: '#000000'},2000);
				
				//	---------------------
				//	Load the Insert form
				$.get('create.php', function(data){
					$("table").append(TransformToTr(data));
				});
				
				$(".delete-link").click(function(){
					$.get(this.href, function(data){
						$(".modal-body").html($(data).find("div.delete"));
					})
					$(".Mdelete").modal({ show: true });
					return false;
				});

				$(".edit-link").click(function(){
					CancelEdit();
					var $tr = $(this).closest("tr").hide();
					$.get(this.href, {date: new Date()}, function(data){
						var $tr2 = TransformToTr(data);
						$tr.after($tr2);
					})
					return false;
				});
				$("form").submit(function(e) {
					var postData = $(this).serialize();
					$.post(this.action, postData + '&ajax=true', function(data){
						if($(data).find(".control-group").length > 0){
							$(".edit-form").replaceWith(TransformToTr(data));
						}else{
							$(".edit-form").replaceWith(data);
						}
					});
                    return false;
                });
				$(".cancel-link").live('click',function(){
					CancelEdit();
					return false;
				});
			});
</script>